﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SIA.Configurators.ods;

namespace SIA.Configurators
{

    /*
    public class FilesDictionaryProperty<TDictionaryProperty> : AbstractDictionaryProperty
        where TDictionaryProperty : OdsDictionaryProperty
    {
        private String _directory;
        private String _filter;
        private System.IO.FileSystemWatcher _fsw;
        public String Directory { get { return _directory; } }


        /// <summary>ctor</summary>
        /// <param name="directory"></param>
        /// <param name="filter">ex. "*.ods", "*.config"</param>
        public FilesDictionaryProperty(String directory, String filter)
        {
            if (!System.IO.Directory.Exists(directory)) throw new System.IO.DirectoryNotFoundException();

            this._directory = directory;
            this._filter = filter;

            load();


            _fsw = new System.IO.FileSystemWatcher(_directory, _filter);
            _fsw.Created += new System.IO.FileSystemEventHandler(_fsw_Created);
            _fsw.Deleted += new System.IO.FileSystemEventHandler(_fsw_Deleted);
            _fsw.Renamed += new System.IO.RenamedEventHandler(_fsw_Renamed);
            _fsw.EnableRaisingEvents = true;
        }

        void _fsw_Renamed(object sender, System.IO.RenamedEventArgs e)
        {
            this.Remove(e.OldName);
            this.Add(e.Name, new TDictionaryProperty(e.FullPath));
        }

        void _fsw_Deleted(object sender, System.IO.FileSystemEventArgs e)
        {
            this.Remove(e.Name);
        }

        void _fsw_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            Add(e.Name, new TDictionaryProperty(e.FullPath));
        }

        public override void load()
        {
            this.Clear();

            foreach (String key in System.IO.Directory.GetFiles(_directory, _filter, System.IO.SearchOption.AllDirectories))
            {
                String key = key.Substring(key.LastIndexOf(System.IO.Path.DirectorySeparatorChar) + 1);
                if (!this.ContainsKey(key))
                    Add(key, new TDictionaryProperty(key));
            }
        }
    }
     */
}
